/**
 * Copyright 2009 by Christian Scheid. This file is part of the switch eclipse plugin and is licensed under the
 * GPL version 3. Please refer to the URL http://www.gnu.org/licenses/gpl-3.0.html for details.
 */
package org.digitalsoul.switchplugin.prefs.wizards;

import org.digitalsoul.switchplugin.prefs.SwitchSetListUI;
import org.digitalsoul.switchplugin.prefs.util.SetConfigurator;

public class NewSetWizard extends NewThingWizard {

    private final SetConfigurator configurator;
    private SwitchSetListUI setListUI;

    public NewSetWizard(SwitchSetListUI setListUI, SetConfigurator configurator) {
        this.setListUI = setListUI;
        this.configurator = configurator;
    }

    @Override
    protected String getLabelText() {
        return "Set Name: ";
    }

    @Override
    protected String getPageDescription() {
        return "Create a new Switch Set";
    }

    @Override
    protected String getPageId() {
        return "new.switch.set.wizard";
    }

    @Override
    protected String getTitle() {
        return "Create Switch Set";
    }

    @Override
    protected boolean validateName(String text) {
        boolean setAlreadyExists = configurator.hasSet(text.trim());
        if (setAlreadyExists) {
            setErrorMessage("A Switch Set with this name already exists");
        }
        else setErrorMessage(null);
        return !setAlreadyExists;
    }

    @Override
    public boolean performFinish() {
        configurator.addNewSet(textField.getText().trim());
        setListUI.refreshListItems();
        setListUI.selectLastItem();
        return true;
    }
}
